<html>
<head><meta charset="utf-8"><title>MBE: mapping spans in IDE · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/MBE.3A.20mapping.20spans.20in.20IDE.html">MBE: mapping spans in IDE</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="163086993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/MBE%3A%20mapping%20spans%20in%20IDE/near/163086993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/MBE.3A.20mapping.20spans.20in.20IDE.html#163086993">(Apr 11 2019 at 10:12)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="153740">@Igor Matuszewski</span> </p>
<p>So, the high level goal here is to make this work:</p>
<div class="codehilite"><pre><span></span>macro_rules! s {
    ($i:ident) =&gt; { struct $i; }
}

s!(Foo); // arrive here

fn foo(_: Foo) { // press go to definition on `Foo` here

}
</pre></div>



<a name="163087089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/MBE%3A%20mapping%20spans%20in%20IDE/near/163087089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/MBE.3A.20mapping.20spans.20in.20IDE.html#163087089">(Apr 11 2019 at 10:14)</a>:</h4>
<p>Currently, go to definition gives the wrong span (which is actually by itself is pretty cool!)</p>



<a name="163087154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/MBE%3A%20mapping%20spans%20in%20IDE/near/163087154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/MBE.3A.20mapping.20spans.20in.20IDE.html#163087154">(Apr 11 2019 at 10:15)</a>:</h4>
<p>key code pointers:</p>
<p>TokenMap: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/e6e2571bdf780d304c792d4317bbaf1d6f5d7a0a/crates/ra_mbe/src/syntax_bridge.rs#L9-L23" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/e6e2571bdf780d304c792d4317bbaf1d6f5d7a0a/crates/ra_mbe/src/syntax_bridge.rs#L9-L23">https://github.com/rust-analyzer/rust-analyzer/blob/e6e2571bdf780d304c792d4317bbaf1d6f5d7a0a/crates/ra_mbe/src/syntax_bridge.rs#L9-L23</a></p>



<a name="163087240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/MBE%3A%20mapping%20spans%20in%20IDE/near/163087240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/MBE.3A.20mapping.20spans.20in.20IDE.html#163087240">(Apr 11 2019 at 10:16)</a>:</h4>
<p>Original FIle function: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/e6e2571bdf780d304c792d4317bbaf1d6f5d7a0a/crates/ra_hir/src/ids.rs#L37-L47" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/e6e2571bdf780d304c792d4317bbaf1d6f5d7a0a/crates/ra_hir/src/ids.rs#L37-L47">https://github.com/rust-analyzer/rust-analyzer/blob/e6e2571bdf780d304c792d4317bbaf1d6f5d7a0a/crates/ra_hir/src/ids.rs#L37-L47</a></p>
<p>It should be extended to return a span-transofmation function as well</p>



<a name="163087345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/MBE%3A%20mapping%20spans%20in%20IDE/near/163087345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/MBE.3A.20mapping.20spans.20in.20IDE.html#163087345">(Apr 11 2019 at 10:18)</a>:</h4>
<p>and here's the exact place where we get the wrgon span for goto definition: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/e6e2571bdf780d304c792d4317bbaf1d6f5d7a0a/crates/ra_ide_api/src/display/navigation_target.rs#L149-L150" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/e6e2571bdf780d304c792d4317bbaf1d6f5d7a0a/crates/ra_ide_api/src/display/navigation_target.rs#L149-L150">https://github.com/rust-analyzer/rust-analyzer/blob/e6e2571bdf780d304c792d4317bbaf1d6f5d7a0a/crates/ra_ide_api/src/display/navigation_target.rs#L149-L150</a></p>



<a name="163087378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/MBE%3A%20mapping%20spans%20in%20IDE/near/163087378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/MBE.3A.20mapping.20spans.20in.20IDE.html#163087378">(Apr 11 2019 at 10:19)</a>:</h4>
<p>note that we call original_file here, which returns the source file (as opposed to the maro pseudo file, where the node actually resides), while the ndoe still has offsets in the macro-generated file</p>



<a name="163087539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/MBE%3A%20mapping%20spans%20in%20IDE/near/163087539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/MBE.3A.20mapping.20spans.20in.20IDE.html#163087539">(Apr 11 2019 at 10:21)</a>:</h4>
<p>btw, might be a good idea to create a GitHub issue for this zulip thread as well</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>